﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LightManager.UserControls
{
    public partial class PlayerControl : UserControl, IUnitRenderer
    {
        public PlayerControl()
        {
            InitializeComponent();
        }

        public Unit DataSource
        {
            get { return this.Tag as Unit; }
            set
            {
                this.Tag = value;
                this.lblName.Text = value.Name;
                this.lblPlayer.Text = value.PlayerName;
                this.lblLifeCount.Text = value.LifeCount.ToString();
                this.lifeStatusControl.DataSource = value;

                //ARMATURA
                this.lblArmor.Text = string.Format("{0} Armatura", value.Armors[DamageSources.Phisical].ToString());
                if (value.Shields[DamageSources.Phisical] > 0)
                    this.lblArmor.Text += string.Format(" \\ {0} Scudo", value.Shields[DamageSources.Phisical].ToString().PadLeft(2, '0'));
                this.toolTip.SetToolTip(this.pctArmor, value.ArmorDescription);

                //RESISTENZE
                string resistances = "";
                foreach (var x in value.Resistances)
                {
                    if (x.Value == 0) continue;
                    resistances += string.Format("{0}% {1} \\ ", x.Value.ToString(), x.Key);
                }
                this.pctResistances.Visible = !string.IsNullOrEmpty(resistances);
                if (!string.IsNullOrEmpty(resistances))
                    this.toolTip.SetToolTip(this.pctResistances, resistances.Substring(0, resistances.Length - 3));

                //AZIONI
                this.lblActions.Text = string.Format("{0} Azioni", value.CurrentActions.ToString());

                this.lblEffects.Text = "";
                foreach (string effect in value.CustomStatus)
                    this.lblEffects.Text += effect + "\r\n";
                //this.Size = new Size(this.Width, this.Height + value.CustomStatus.Count * 8);

                //AVATAR
                if (!string.IsNullOrEmpty(value.ImageFile))
                    if (System.IO.File.Exists(System.IO.Path.Combine(Application.StartupPath, value.ImageFile)))
                        this.pctAvatar.Image = new Bitmap(System.IO.Path.Combine(Application.StartupPath, value.ImageFile));
            }
        }
    }
}
